package top.superxuqc.autocheckincqupt.checkinconsumer.controller;


import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import top.superxuqc.autocheckincqupt.checkinconsumer.domain.CQUPTStu;
import top.superxuqc.autocheckincqupt.checkinconsumer.service.DealCheckService;
import top.superxuqc.autocheckincqupt.domain.ApiResult;

import java.util.List;

@Controller
public class BaseController {

    @Autowired
    DealCheckService checkService;

    @RequestMapping("/save")
    @ResponseBody
    public String save(CQUPTStu stu){
        ApiResult<List<String>> result = checkService.tryCheck(stu);
        if(!result.getCode().equals("200")){
            return "错误，请检查参数重试 \n" + JSONObject.toJSONString(result);
        }
        checkService.save(stu);
        return "success! \n" + JSONObject.toJSONString(result);
    }


    @RequestMapping("/")
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView("index");
        System.out.println("进来了");
        return mv;
    }

    @RequestMapping("/x/v/once")
    @ResponseBody
    public String once(String pwd){
        if(pwd.equals("xqcxqc")){
            checkService.check();
            return "成功";
        }else {
            return "嘎哈？乱访问啥呢";
        }

    }
}
